/*
	Copyright (c) 2011 Andrey O. Zbitnev (azbitnev@gmail.com)
	Licensed under the MIT License (LICENSE).

	$Id: ys.effects.js 8 2012-04-10 12:57:10Z azbitnev@gmail.com $

	version: 0.2pa

	required modules: core
*/

(function () {

	$.ys.effects = {

		showSlideDown: function (selector, options) {

			var defaults = {
				duration: 'fast',
				easing: 'linear',
				flag: 'ys-show',
				callback: function ($el) { }
			}

			var opts = $.extend(defaults, options);

			var $c = $(selector), flag = opts.flag
			if (!$c.data(flag)) {
				$c.data(flag, true)
				var h = $.ys.fn.height($c.children('div:eq(0)'))
				$c.css({ visibility: 'visible', height: 0 })
					.scrollTop(h)
					.animate({
						height: '' + h + 'px',
						scrollTop: h
						},
						opts.duration,
						opts.easing,
						function () {
							$c.scrollTop(0)
								.css({ height: 'auto' })
								.data(flag, false)
							if (opts.callback)
								opts.callback($c)
						}
					)
			}
		},

		showSlideUp: function (selector, options) {

			var defaults = {
				duration: 'fast',
				easing: 'linear',
				flag: 'ys-show',
				callback: function ($el) { }
			}

			var opts = $.extend(defaults, options);

			var $c = $(selector), flag = opts.flag
			if (!$c.data(flag)) {
				$c.data(flag, true)
				var h = $.ys.fn.height($c.children('div:eq(0)'))
				$c.css({ visibility: 'visible', height: 0, position: 'relative', top: '' + h + 'px' })
					.animate({
						top: 0,
						height: '' + h + 'px'
						},
						opts.duration,
						opts.easing,
						function () {
							$c.css({ height: 'auto' })
								.data(flag, false)
							if (opts.callback)
								opts.callback($c)
						}
					)
			}
		},

		showSlideRight: function (selector, options) {

			var defaults = {
				duration: 'fast',
				easing: 'linear',
				flag: 'ys-show',
				callback: function ($el) { }
			}

			var opts = $.extend(defaults, options);

			var $c = $(selector), flag = opts.flag
			if (!$c.data(flag)) {
				$c.data(flag, true)
				var $cc = $c.children('div:eq(0)'),
					w = $.ys.fn.width($cc), h = $.ys.fn.height($cc)
				$cc.css({ width: '' + w + 'px', height: '' + h + 'px', overflow: 'hidden' })
				$c.css({ visibility: 'visible', width: 0 })
					.scrollLeft(w)
					.animate({
						width: '' + w + 'px',
						scrollLeft: w
						},
						opts.duration,
						opts.easing,
						function () {
							$c.scrollLeft(0).css({ width: 'auto' }).data(flag, false)
							if (opts.callback)
								opts.callback($c)
						}
					)
			}
		},

		showSlideLeft: function (selector, options) {

			var defaults = {
				duration: 'fast',
				easing: 'linear',
				flag: 'ys-show',
				callback: function ($el) { }
			}

			var opts = $.extend(defaults, options);

			var $c = $(selector), flag = opts.flag
			if (!$c.data(flag)) {
				$c.data(flag, true)
				var $cc = $c.children('div:eq(0)'),
					w = $.ys.fn.width($cc), h = $.ys.fn.height($cc)
				$cc.css({ width: '' + w + 'px', height: '' + h + 'px', overflow: 'hidden' })
				$c.css({ visibility: 'visible', width: 0, position: 'relative', left: '' + w + 'px' })
					.animate({
						left: 0,
						width: '' + w + 'px'
						},
						opts.duration,
						opts.easing,
						function () {
							$c.css({ width: 'auto' }).data(flag, false)
							if (opts.callback)
								opts.callback($c)
						}
					)
			}
		},

		hideSlideUp: function (selector, options) {

			var defaults = {
				duration: 'fast',
				easing: 'linear',
				flag: 'ys-hide',
				callback: function ($el) { }
			}

			var opts = $.extend(defaults, options);

			var $c = $(selector), flag = opts.flag
			if (!$c.data(flag)) {
				$c.data(flag, true)
				var h = $.ys.fn.height($c.children('div:eq(0)')), sh = $c.css('height')
				$c.scrollTop(h)
					.animate({
						height: '0px',
						scrollTop: h
						},
						opts.duration,
						opts.easing,
						function () {
							$c.scrollTop(0).css({ visibility: 'hidden', height: sh })
								.data(flag, false)
							if (opts.callback)
								opts.callback($c)
						}
					)
			}
		},

		hideSlideDown: function (selector, options) {

			var defaults = {
				duration: 'fast',
				easing: 'linear',
				flag: 'ys-hide',
				callback: function ($el) { }
			}

			var opts = $.extend(defaults, options);

			var $c = $(selector), flag = opts.flag
			if (!$c.data(flag)) {
				$c.data(flag, true)
				var h = $.ys.fn.height($c.children('div:eq(0)')), sh = $c.css('height')
				$c.css({ position: 'relative', top: 0 })
					.animate({
						top: '' + h + 'px',
						height: '0px'
						},
						opts.duration,
						opts.easing,
						function () {
							$c.css({ visibility: 'hidden', top: 0, height: sh })
								.data(flag, false)
							if (opts.callback)
								opts.callback($c)
						}
					)
			}
		},

		hideSlideRight: function (selector, options) {

			var defaults = {
				duration: 'fast',
				easing: 'linear',
				flag: 'ys-show'
			}

			var opts = $.extend(defaults, options);

			var $c = $(selector), flag = opts.flag
			if (!$c.data(flag)) {
				$c.data(flag, true)
				var $cc = $c.children('div:eq(0)'),
					w = $.ys.fn.width($cc), h = $.ys.fn.height($cc),
					sw = $c.css('width')
				$cc.css({ width: '' + w + 'px', height: '' + h + 'px', overflow: 'hidden' })
				$c.css({ position: 'relative', left: 0 })
					.animate({
						left: '' + w + 'px',
						width: 0
						},
						opts.duration,
						opts.easing,
						function () {
							$c.css({ visibility: 'hidden', left: 0, width: sw })
								.data(flag, false)
							if (opts.callback)
								opts.callback($c)
						}
					)
			}
		},

		hideSlideLeft: function (selector, options) {

			var defaults = {
				duration: 'fast',
				easing: 'linear',
				flag: 'ys-show',
				callback: function ($el) { }
			}

			var opts = $.extend(defaults, options);

			var $c = $(selector), flag = opts.flag
			if (!$c.data(flag)) {
				$c.data(flag, true)
				var $cc = $c.children('div:eq(0)'),
					w = $.ys.fn.width($cc), h = $.ys.fn.height($cc),
					sw = $c.css('width')
				$cc.css({ width: '' + w + 'px', height: '' + h + 'px', overflow: 'hidden' })
				$c.scrollLeft(w)
					.animate({
						width: 0,
						scrollLeft: w
						},
						opts.duration,
						opts.easing,
						function () {
							$c.scrollLeft(0).css({ visibility: 'hidden', width: sw })
								.data(flag, false)
							if (opts.callback)
								opts.callback($c)
						}
					)
			}
		}
	}

})();

